package com.rw.controller;

import com.rw.pojo.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "TestServlet", value = "/test")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getSession().setAttribute("msg","来至session的数据");
        request.getSession().setAttribute("data","来至session的Data数据");
        request.setAttribute("data","来至request的数据");


        List<User> users = new ArrayList<>();
        User u = new User(1,"李四","12345");
        User u1 = new User(2,"李四2","12345");
        User u2 = new User(3,"李四3","12345");
        users.add(u);
        users.add(u1);
        users.add(u2);
        request.setAttribute("list",users);
        request.getRequestDispatcher("./test.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
